import * as mUtils from '@/util/mUtils'
let noticeInfo=[];
const num=100;
for(let i=1;i<=num;i++){
    noticeInfo.push({
        noticeId: i.toString(),
        title: '计算机科学与工程学院',
        content: i+'到校时间为9号，任何人不得提前返校，具体详情...',
        college:'957',
        object:2,
        beginTime: '2019-08-28 00:01:43',
        endTime: '2020-08-28 00:01:43',
    });
}
export default {
    getNotice: config =>{
        //college,collegeId,token
        const { currentPage, rows } = mUtils.param2Obj(config.url);
        const list = noticeInfo.filter((item,index) => index < rows * currentPage && index >= rows * (currentPage - 1))
        return { // 得到消息
            data: {
                simpleNoticeInfo:list,
                count:noticeInfo.length,
            },
            code: 1,
            msg: "登录成功",
        }
    },
    deleteNotice:config=>{
        //token
        const {noticeId } = mUtils.param2Obj(config.url);
        noticeInfo=noticeInfo.filter(item=>item.noticeId!==noticeId);
        return {
            data:{},
            code:1,
            msg:'删除消息成功'
        }
    },
    noticeInfo:config=>{
        //token
        const {noticeId } = mUtils.param2Obj(config.url);
        const list=noticeInfo.filter(item=>item.noticeId===noticeId)
        const noticeInfotest={
            noticeId:list[0].noticeId,
            title:list[0].title,
            content: list[0].content,
            beginTime: list[0].beginTime,
            endTime: list[0].endTime,
            college:list[0].college,
            object:list[0].object
        }
        return {
            data:{
                noticeInfo:noticeInfotest
        },
        code:1,
            msg:'查找消息成功'
    }
    },
    addNotice:config=>{
        let imf = mUtils.param2ObjPost(config.body);
        const info={
                noticeId: (Math.floor(Math.random()*100)+100).toString(),
                title: imf['noticeInfo[title]'],
                content: imf['noticeInfo[content]'],
                college: imf['noticeInfo[college]'],
                object: imf['noticeInfo[object]'],
                beginTime: imf['noticeInfo[beginTime]'],
                endTime: imf['noticeInfo[endTime]'],
        };
        noticeInfo.unshift(info);
        return{
            data:{
            },
            code:1,
            msg:'添加通知成功'
        }
    },

}
